package cn.iocoder.yudao.module.system.repository.mybatis.dao.dept;

import cn.iocoder.yudao.common.pojo.PageResult;
import cn.iocoder.yudao.core.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.core.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.repository.mybatis.domain.dept.Post;
import cn.iocoder.yudao.module.system.vo.dept.post.PostExportReqVO;
import cn.iocoder.yudao.module.system.vo.dept.post.PostPageReqVO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;
import java.util.List;

@Mapper
public interface PostMapper extends BaseMapperX<Post> {

    default List<Post> selectList(Collection<Long> ids, Collection<Integer> statuses) {
        return selectList(new LambdaQueryWrapperX<Post>()
                .inIfPresent(Post::getId, ids)
                .inIfPresent(Post::getStatus, statuses));
    }

    default PageResult<Post> selectPage(PostPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<Post>()
                .likeIfPresent(Post::getCode, reqVO.getCode())
                .likeIfPresent(Post::getName, reqVO.getName())
                .eqIfPresent(Post::getStatus, reqVO.getStatus())
                .orderByDesc(Post::getId));
    }

    default List<Post> selectList(PostExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<Post>()
                .likeIfPresent(Post::getCode, reqVO.getCode())
                .likeIfPresent(Post::getName, reqVO.getName())
                .eqIfPresent(Post::getStatus, reqVO.getStatus()));
    }

    default Post selectByName(String name) {
        return selectOne(Post::getName, name);
    }

    default Post selectByCode(String code) {
        return selectOne(Post::getCode, code);
    }

}
